package com.wjc.wjc.web;


import com.wjc.wjc.service.NewService;
import com.wjc.wjc.unity.News;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.ArrayList;
import java.util.List;

@Controller
public class NoticesController {

    @Autowired
    private NewService newService;

    @GetMapping("/notice")
    public String notice(Model model){

        List<News> list=newService.listNews();
        News news=list.get(0);
        System.out.println(news.toString());
        model.addAttribute("n",news);
        model.addAttribute("news",list);
        return "notice";
    }

    @PostMapping("/notice/c")
    public String noticeById(@RequestParam Long id, Model model){
        model.addAttribute("n",newService.getNew(id));
        return "/notice :: ns";
    }
}
